package com.sky.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sky.dto.AlertDTO;
import com.sky.dto.AlertPageQueryDTO;
import com.sky.entity.ViolationRecord;
import com.sky.mapper.AlertMapper;
import com.sky.result.PageResult;
import com.sky.service.AlertService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AlertServiceImpl implements AlertService {
    @Autowired
    private AlertMapper alertMapper;
    @Override
    public PageResult pageQuery(AlertPageQueryDTO pageQuery) {
        //1、设置当前页和每页条数
        PageHelper.startPage(pageQuery.getPage(),pageQuery.getPageSize());
        Page<ViolationRecord> page =alertMapper.pageQuery(pageQuery);
        long total = page.getTotal();
        List<ViolationRecord> records = page.getResult();
        return new PageResult(total,records);
    }

    @Override
    public void process(AlertDTO alertDTO) {
        alertMapper.update(alertDTO);

    }

    public void updateWarningLevel(AlertDTO alertDTO) {
        alertMapper.updateLevelAndViolation(alertDTO);
    }

}
